package com.zpiz.controller;





import com.apiz.model.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/name")
public class NameController {

    @GetMapping("/get")
    public String getNameByGet(String name, HttpServletRequest request){

        System.out.println(request.getHeader("zhb"));
        return "GET 你的名字是"+name;
    }

    @PostMapping("/post")
    public String getNameByPost(@RequestParam String name){
        return "POST 你的名字是"+name;
    }

    @PostMapping("/user")
    public String getUserNameByPost(@RequestBody User user, HttpServletRequest request){

//        String accessKey = request.getHeader("accessKey");
//        String nonce = request.getHeader("nonce");
//        String body = request.getHeader("body");
//        String timeStamp = request.getHeader("timeStamp");
//        String sign = request.getHeader("sign");
//
//
//        //todo accessKey 去数据库查 是否已分配给用户
//        if (!accessKey.equals("zhb")){
//            throw new RuntimeException("参数错误");
//        }
//
//        if (Long.parseLong(nonce) > 10000){
//            throw new RuntimeException("参数错误");
//        }
//        //todo 和当前时间不能超过5分钟
////        if (timeStamp){
////
////        }
//        String serverSign = SignUtil.getSign(body,"abcd");
//        if (!sign.equals(serverSign)){
//            throw new RuntimeException("参数错误");
//        }
        return user.getUsername();
    }

}
